package com.example.config.listener;

import com.example.config.common.Constants;
import com.example.config.event.ConfigModifyEvent;
import com.example.config.initializer.CustomizableEnvironmentInitializer;
import com.example.config.properties.RemoteProperties;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;

/**
 * @author <a href="juntao.zhang@bkjk.com">juntao.zhang</a>
 * @Description:
 * @Package com.example.config.listener
 * @date 2017/12/13 19:40
 * @see
 */
public class RemoteConfigListener implements ApplicationListener<ApplicationEvent> {
    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof ApplicationStartedEvent){
            Constants.remotePropertiesResource = new RemoteProperties("zhang-demo",3);
            Constants.remotePropertiesResource.loadResource();
        }
        /*if (event instanceof ApplicationPreparedEvent) {
            CustomizableEnvironmentInitializer.source.loadResource();
        }*/
        else if (event instanceof ConfigModifyEvent) {
            Constants.remotePropertiesResource.loadResource();
        }
    }
}
